// packageE/memberorder/memberorder.js
Component({
  properties: {
    datas: {
      type: null,
    },
    component_id: {
      type: null,
    },
    member_order: {
      type: null,
    },
  },
  // 私有数据，可用于模板渲染
  data: {
    emptyImage: "https://mini-app-img-1251768088.cos.ap-guangzhou.myqcloud.com/image.png",
    active: "",
    U_memberorder: [{
      label: "waitPay",
      value: 0
    },
    {
      label: "waitSend",
      value: 0
    },
    {
      label: "waitReceive",
      value: 0
    },
    {
      label: "waitrRefund",
      value: 0
    },
    ],
    U_memberorderhotel: [{
      label: "waitPay",
      value: 0
    },
    {
      label: "waitSure",
      value: 0
    },
    {
      label: "waitEnter",
      value: 0
    },
    {
      label: "waitCheckOut",
      value: 0
    },
    ],
    U_memberorderrelease: [{
      label: "waitPay",
      value: 0
    },
    {
      label: "waitSend",
      value: 0
    },
    {
      label: "waitReceive",
      value: 0
    },
    {
      label: "waitrRefund",
      value: 0
    },
    ],
    U_yzSupplyLease: [{
      label: "waitPay",
      value: 0
    },
    {
      label: "waitSend",
      value: 0
    },
    {
      label: "waitReceive",
      value: 0
    },
    {
      label: "waitrRefund",
      value: 0
    },
    ],
    U_memberordergroup: [{
      label: "",
      value: 0
    },
    {
      label: "waitPay",
      value: 0
    },
    {
      label: "waitSend",
      value: 0
    },
    {
      label: "waitReceive",
      value: 0
    },
    {
      label: "waitrRefund",
      value: 0
    },
    ],
    U_memberordergroup_ywm: [{
      label: "",
      value: 0
    },
    {
      label: "waitPay",
      value: 0
    },
    {
      label: "waitSend",
      value: 0
    },
    {
      label: "waitReceive",
      value: 0
    },
    {
      label: "waitrRefund",
      value: 0
    },
    ],
    U_memberordergrab: [{
      label: "waitPay",
      value: 0
    },
    {
      label: "waitSend",
      value: 0
    },
    {
      label: "waitReceive",
      value: 0
    },
    {
      label: "waitrRefund",
      value: 0
    },
    ],
    U_memberorderlive_install: [{
      status: 0,
      value: 0
    },
    {
      status: 1,
      value: 0
    },
    {
      status: 2,
      value: 0
    },
    {
      status: 3,
      value: 0
    },
    {
      status: 5,
      value: 0
    }
    ],
    U_memberorderlive_install_worker: [{
      status: 0,
      value: 0
    },
    {
      status: 1,
      value: 0
    },
    {
      status: 2,
      value: 0
    },
    {
      status: 3,
      value: 0
    },
    {
      status: 5,
      value: 0
    }
    ],
    U_memberordercps: [{
      status: -1,
      value: 0
    },
    {
      status: 0,
      value: 0
    },
    {
      status: 1,
      value: 0
    },
    {
      status: 2,
      value: 0
    }
    ],
    U_memberordernew_group: [{
      label: "waitPay",
      value: 0
    },
    {
      label: "waitSend",
      value: 0
    },
    {
      label: "waitReceive",
      value: 0
    },
    {
      label: "waitrRefund",
      value: 0
    },
    ],
    //蛋糕叔叔
    U_yz_supply_cake: [{
      label: "waitPay",
      value: 0
    },
    {
      label: "waitSend",
      value: 0
    },
    {
      label: "waitReceive",
      value: 0
    },
    {
      label: "waitrRefund",
      value: 0
    },
    ],
    U_coupon_store_order: [{value: 0},{value: 0},{value: 0},{value: 0},],
    U_unionCps_order: {},
    U_travelAround: {}
  },
  lifetimes: {
    // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
    attached() {
      if (this.data.member_order && this.data.member_order.order) {
        for (let i = 0; i < this.data.member_order.order.length; i++) {
          // 0 待付款 1待发货 2待收货 3完成
          let item = this.data.member_order.order[i];
          if (item.status == 0) {
            this.setData({
              ["U_memberorder[0].value"]: item.total,
            });
          } else if (item.status == 1) {
            this.setData({
              ["U_memberorder[1].value"]: item.total,
            });
          } else if (item.status == 2) {
            this.setData({
              ["U_memberorder[2].value"]: item.total,
            });
          } else if (item.status == 11) {
            this.setData({
              ["U_memberorder[3].value"]: item.total,
            });
          }
        }
      }

      if (this.data.member_order && this.data.member_order.hotel_order) {
        this.data.member_order.hotel_order.forEach((item) => {
          if (item.status == 0) {
            this.setData({
              ["U_memberorderhotel[0].value"]: item.total,
            });
          } else if (item.status == 1) {
            this.setData({
              ["U_memberorderhotel[1].value"]: item.total,
            });
          } else if (item.status == 2) {
            this.setData({
              ["U_memberorderhotel[2].value"]: item.total,
            });
          } else if (item.status == 11) {
            this.setData({
              ["U_memberorderhotel[3].value"]: item.total,
            });
          }
        });
      }

      if (this.data.member_order && this.data.member_order.lease_order) {
        this.data.member_order.lease_order.forEach((item) => {
          if (item.status == "0") {
            this.setData({
              ["U_memberorderrelease[0].value"]: item.total,
            });
          } else if (item.status == "1") {
            this.setData({
              ["U_memberorderrelease[1].value"]: item.total,
            });
          } else if (item.status == "2") {
            this.setData({
              ["U_memberorderrelease[2].value"]: item.total,
            });
          } else if (item.status == "3") {
            this.setData({
              ["U_memberorderrelease[3].value"]: item.total,
            });
          }
        });
      }

      if (this.data.member_order && this.data.member_order.yz_supply_lease_order) {
        this.data.member_order.yz_supply_lease_order.forEach((item) => {
          if (item.status == "0") {
            this.setData({
              ["U_yzSupplyLease[0].value"]: item.total,
            });
          } else if (item.status == "1") {
            this.setData({
              ["U_yzSupplyLease[1].value"]: item.total,
            });
          } else if (item.status == "2") {
            this.setData({
              ["U_yzSupplyLease[2].value"]: item.total,
            });
          } else if (item.status == "3") {
            this.setData({
              ["U_yzSupplyLease[3].value"]: item.total,
            });
          }
        });
      }

      if (this.data.member_order && this.data.member_order.fight_groups_order) {
        this.data.member_order.fight_groups_order.forEach((item) => {
          if (item.status == 0) {
            this.setData({
              ["U_memberordergroup[1].value"]: item.total,
            });
          } else if (item.status == 1) {
            this.setData({
              ["U_memberordergroup[2].value"]: item.total,
            });
          } else if (item.status == 2) {
            this.setData({
              ["U_memberordergroup[3].value"]: item.total,
            });
          } else if (item.status == 11) {
            this.setData({
              ["U_memberordergroup[4].value"]: item.total,
            });
          }
        });
      }

      if (this.data.member_order && this.data.member_order.ywm_fight_groups_order) {
        this.data.member_order.ywm_fight_groups_order.forEach((item) => {
          if (item.status == 1) {
            this.setData({
              ["U_memberordergroup_ywm[1].value"]: item.total,
            });
          } else if (item.status == 3) {
            this.setData({
              ["U_memberordergroup_ywm[2].value"]: item.total,
            });
          } else if (item.status == 4) {
            this.setData({
              ["U_memberordergroup_ywm[3].value"]: item.total,
            });
          } else if (item.status == 11) {
            this.setData({
              ["U_memberordergroup_ywm[4].value"]: item.total,
            });
          }
        });
      }

      if (
        this.data.member_order &&
        this.data.member_order.snatch_regiment_order
      ) {
        this.data.member_order.snatch_regiment_order.forEach((item) => {
          if (item.status == 0) {
            this.setData({
              ["U_memberordergrab[0].value"]: item.total,
            });
          } else if (item.status == 1) {
            this.setData({
              ["U_memberordergrab[1].value"]: item.total,
            });
          } else if (item.status == 2) {
            this.setData({
              ["U_memberordergrab[2].value"]: item.total,
            });
          } else if (item.status == 11) {
            this.setData({
              ["U_memberordergrab[3].value"]: item.total,
            });
          }
        });
      }

      if (
        this.data.member_order &&
        this.data.member_order.live_install_order
      ) {
        this.data.member_order.live_install_order.forEach((item) => {
          if (item.status == 0) {
            this.setData({
              ["U_memberorderlive_install[0].value"]: item.total,
            });
          } else if (item.status == 1) {
            this.setData({
              ["U_memberorderlive_install[1].value"]: item.total,
            });
          } else if (item.status == 2) {
            this.setData({
              ["U_memberorderlive_install[2].value"]: item.total,
            });
          } else if (item.status == 3) {
            this.setData({
              ["U_memberorderlive_install[4].value"]: item.total,
            });
          }
        });
      }

      if (
        this.data.member_order &&
        this.data.member_order.live_install_work_order
      ) {
        this.data.member_order.live_install_work_order.forEach((item) => {
          if (item.status == 2) {
            this.setData({
              ["U_memberorderlive_install_worker[0].value"]: item.total,
            });
          } else if (item.status == 3) {
            this.setData({
              ["U_memberorderlive_install_worker[1].value"]: item.total,
            });
          } else if (item.status == 4) {
            this.setData({
              ["U_memberorderlive_install_worker[2].value"]: item.total,
            });
          } else if (item.status == 6) {
            this.setData({
              ["U_memberorderlive_install_worker[4].value"]: item.total,
            });
          }
        });
      } else {
        this.data.datas.list = this.data.datas.list.filter((item) => {
          return item.uikey != 'U_memberorderlive_install_worker';
        });
        this.setData({
          'datas.list': this.data.datas.list
        });
      }

      if (
        this.data.member_order &&
        this.data.member_order.aggregation_cps_order
      ) {
        this.data.member_order.aggregation_cps_order.forEach((item) => {
          if (item.status == 1) {
            this.setData({
              ["U_memberordercps[2].value"]: item.total,
            });
          } else if (item.status == 2) {
            this.setData({
              ["U_memberordercps[3].value"]: item.total,
            });
          } else if (item.status == -1) {
            this.setData({
              ["U_memberordercps[0].value"]: item.total,
            });
          }
        });
      }

      if (this.data.member_order && this.data.member_order.group_work_order) {
        for (let i = 0; i < this.data.member_order.group_work_order.length; i++) {
          // 0 待付款 1待发货 2待收货 3完成
          let item = this.data.member_order.group_work_order[i];
          if (item.status == 0) {
            this.setData({
              ["U_memberordernew_group[0].value"]: item.total,
            });
          } else if (item.status == 1) {
            this.setData({
              ["U_memberordernew_group[1].value"]: item.total,
            });
          } else if (item.status == 2) {
            this.setData({
              ["U_memberordernew_group[2].value"]: item.total,
            });
          } else if (item.status == 11) {
            this.setData({
              ["U_memberordernew_group[3].value"]: item.total,
            });
          }
        }
      }
      //蛋糕叔叔
      if (this.data.member_order && this.data.member_order?.yz_supply_cake_order) {
        for (let i = 0; i < this.data.member_order.yz_supply_cake_order.length; i++) {
          // 0 待付款 1待发货 2待收货 3完成
          let item = this.data.member_order.yz_supply_cake_order[i];
          if (item.status == 0) {
            this.setData({
              ["U_yz_supply_cake[0].value"]: item.total,
            });
          } else if (item.status == 1) {
            this.setData({
              ["U_yz_supply_cake[1].value"]: item.total,
            });
          } else if (item.status == 2) {
            this.setData({
              ["U_yz_supply_cake[2].value"]: item.total,
            });
          } else if (item.status == 3) {
            this.setData({
              ["U_yz_supply_cake[3].value"]: item.total,
            });
          }
        }
      }

      if (this.data.member_order.yz_union_cps_order) {
        this.data.member_order.yz_union_cps_order.map(item => {
          this.data.U_unionCps_order[item.status] = item.total;
        });
        this.setData({
          U_unionCps_order: this.data.U_unionCps_order
        })
      }

      if (this.data.member_order.travel_around_order) {
        this.data.member_order.travel_around_order.map(item => {
          this.data.U_travelAround[item.status] = item.total;
        });
        this.setData({
          U_travelAround: this.data.U_travelAround
        })
      }

      if (this.data.member_order && this.data.member_order.coupon_store_order) {
        let _index = 0;
        let _list = this.data.datas.list[_index].datas.list.value;
        this.data.datas.list.map((el,i) => {
          if(el.uikey == 'U_coupon_store_order'){
            _index = i;
          }
        });
        
        _list.map(el => {
          el.total = this.data.member_order.coupon_store_order.find(item => item.status == el.id)?.total||0;
        });
        this.setData({
          ['datas.list[' + _index + '].datas.list.value']: _list
        });
      }
    },
    moved() {},
    detached() {},
  },

  // 生命周期函数，可以为函数，或一个在methods段中定义的方法名
  attached() {},
  // 此处attached的声明会被lifetimes字段中的声明覆盖
  ready() {},

  pageLifetimes: {
    // 组件所在页面的生命周期函数
    show() {},
    hide() {},
    resize() {},
  },
  methods: {
    bindTags(evt) {
      let index = evt.detail.index;
      this.setData({
        active: index,
      });
      if (this.data.datas.list[index].uikey == "U_memberorder_ys") {
        // 益生线下订单
        wx.navigateTo({
          url: "/packageA/member/myOrder_v2/myOrder_v2?status=0&orderType=ysSystem",
        });
        return false;
      }
    },
    goAllOrderlist: function (e) {
      let ordertype = "";
      switch (this.data.datas.list[0].uikey) {
      case "U_memberorder":
        ordertype = "";
        break;
      case "U_memberorderhotel":
        ordertype = "hotel";
        break;
      case "U_memberorderrelease":
        ordertype = "lease_toy";
        break;
      case "U_yzSupplyLease":
        ordertype = "yz_lease_toy";
        break;
      case "U_memberordergroup":
        ordertype = "groups";
        break;
      case "U_memberordergroup_ywm":
        ordertype = "ywmgroups";
        break;
      case "U_memberordergrab":
        ordertype = "grabGroup";
        break;
      case "U_memberordernew_group":
        ordertype = "groupWork";
        break;
      case "U_memberorder_ys":
        ordertype = "ysSystem";
        break;
      case "U_yz_supply_cake":
        ordertype = "sachertorte";
        break;
      }
      let title = e.currentTarget.dataset.name;
      wx.navigateTo({
        url: "/packageA/member/myOrder_v2/myOrder_v2?status=0&orderType=" + ordertype + "&title=" + title,
      });
    },
    //跳到我的订单详情页面
    goorderlist: function (e) {
      //orderlist
      let {status,name} = e.currentTarget.dataset;
      if (status == 4) {
        wx.navigateTo({
          url: "/packageD/member/myOrder/Aftersaleslist/Aftersaleslist",
        });
        return;
      }
      wx.navigateTo({
        url: "/packageA/member/myOrder_v2/myOrder_v2?status=" + status + "&title=" + name,
      });
    },
    gohotelOrderlist(e) {
      let {status,name} = e.currentTarget.dataset;
      wx.navigateTo({
        url: "/packageA/member/myOrder_v2/myOrder_v2?status=" +
          status +
          "&orderType=hotel" + "&title=" + name,
      });
    },
    goleaseOrderlist(e) {
      let {status,name} = e.currentTarget.dataset;
      if(e.currentTarget.dataset.type == 'yz_lease_toy'){
        wx.navigateTo({
          url: "/packageA/member/myOrder_v2/myOrder_v2?status=" +
            status +
            "&orderType=yz_lease_toy" + "&title=" + name,
        });
        return
      }
      wx.navigateTo({
        url: "/packageA/member/myOrder_v2/myOrder_v2?status=" +
          status +
          "&orderType=lease_toy" + "&title=" + name,
      });
    },
    gogroupOrderlist(e) {
      let {status,name} = e.currentTarget.dataset;
      if (status == 5) {
        wx.navigateTo({
          url: "/packageD/member/myOrder/Aftersaleslist/Aftersaleslist?orderType=groups",
        });
        return;
      }
      wx.navigateTo({
        url: "/packageA/member/myOrder_v2/myOrder_v2?status=" +
          status +
          "&orderType=groups" + "&title=" + name,
      });
    },
    goywmgroupOrderlist(e) {
      let {status,name} = e.currentTarget.dataset;
      if (status == 5) {
        wx.navigateTo({
          url: "/packageD/member/myOrder/Aftersaleslist/Aftersaleslist?orderType=ywmgroups",
        });
        return;
      }
      if (status == 2) {
        wx.navigateTo({
          url: "/packageA/member/myOrder_v2/myOrder_v2?status=1&orderType=ywmgroups"
        });
        return;
      }
      wx.navigateTo({
        url: "/packageA/member/myOrder_v2/myOrder_v2?status=" +
          status +
          "&orderType=ywmgroups" + "&title=" + name,
      });
    },
    gograbOrderlist(e) {
      let {status,name} = e.currentTarget.dataset;
      wx.navigateTo({
        url: "/packageA/member/myOrder_v2/myOrder_v2?status=" +
          status +
          "&orderType=grabGroup" + "&title=" + name,
      });
    },
    cakeOrderList(e) {
      let {status,name,type} = e.currentTarget.dataset;
      wx.navigateTo({
        url: `/packageA/member/myOrder_v2/myOrder_v2?status=${status}&orderType=${type}&title=${name}`,
      });
    },
    tiktokCpsOrder(e){
      let {status} = e.currentTarget.dataset;
      wx.navigateTo({
        url: `/packageF/cps/order/order?status=${status}`,
      });
    },
    golive_installOrderlist(e) {
      let {status,name} = e.currentTarget.dataset;
      wx.navigateTo({
        url: "/packageH/installationSever/installationSeverMemberHome/installationSeverMemberHome?status=" + status + "&title=" + name,
      });
    },
    golive_install_workOrderlist(e) {
      let {status,name} = e.currentTarget.dataset;
      if (status == -1) {
        wx.navigateTo({
          url: "/packageH/installationSever/installationSeverHome/installationSeverHome?status=1",
        });
        return;
      }
      wx.navigateTo({
        url: "/packageH/installationSever/installationSeverHome/installationSeverHome?status=" + status + "&title=" + name,
      });
    },
    gocpsOrderlist(e) {
      let {status,name} = e.currentTarget.dataset;
      if (status == 3) {
        wx.navigateTo({
          url: "/packageA/member/order/cpsCoupon/cpsCoupon" + "?title=" + name,
        });
        return;
      }
      wx.navigateTo({
        url: "/packageA/member/order/cpsOrder/cpsOrder?status=" + status + "&title=" + name,
      });
    },
    goGroupWorkorderlist: function (e) {
      //orderlist
      let {status,name} = e.currentTarget.dataset;
      if (status == 4) {
        wx.navigateTo({
          url: "/packageD/member/myOrder/Aftersaleslist/Aftersaleslist",
        });
        return;
      }
      wx.navigateTo({
        url: "/packageA/member/myOrder_v2/myOrder_v2?status=" + status + "&orderType=groupWork" + "&title=" + name,
      });
    },
    goCouponStorederlist: function (e) {
      //orderlist
      let {status,name} = e.currentTarget.dataset;
      if (status == -1) {
        wx.navigateTo({
          url: "/packageD/member/myOrder/Aftersaleslist/Aftersaleslist",
        });
        return;
      }
      wx.navigateTo({
        url: "/packageF/consumption/orderList/orderList?status=" + status + "&title=" + name,
      });
    },
    unionCpsOrder(e){
      let {status} = e.currentTarget.dataset;
      wx.navigateTo({
        url: `/packageJ/unionCps/order/order?status=${status}`,
      });
    },
    travelAroundOrder(e){
      let {status} = e.currentTarget.dataset;
      wx.navigateTo({
        url: `/packageA/member/myOrder_v2/myOrder_v2?status=${status}&orderType=travelAround`,
      });
    },
  },
  observers: {
    "member_order.**": function (res) {
      // 每次 setData 都触发
      if (res) {
        for (let i = 0; i < res.order.length; i++) {
          // 0 待付款 1待发货 2待收货 3完成
          let item = res.order[i];
          if (item.status == 0) {
            this.setData({
              ["U_memberorder[0].value"]: item.total,
            });
          } else if (item.status == 1) {
            this.setData({
              ["U_memberorder[1].value"]: item.total,
            });
          } else if (item.status == 2) {
            this.setData({
              ["U_memberorder[2].value"]: item.total,
            });
          } else if (item.status == 11) {
            this.setData({
              ["U_memberorder[3].value"]: item.total,
            });
          }
        }
      }
    },
  },
});